{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This allows multiple outputs from a single jupyter notebook cell:\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.3'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "import pandas as pd\n",
    "pd.__version__  # for the record"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Check Use Cases:\n",
    "---\n",
    "### Here we run through many cases of different amounts and densities of data, intraday, daily, weekly, and multiple styles to make sure all look OK for a given change \n",
    "### ... for example correcting candle widths, volume bar widths, etc.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(252, 9)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>UpperB</th>\n",
       "      <th>LowerB</th>\n",
       "      <th>PercentB</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-07-01</th>\n",
       "      <td>132.089996</td>\n",
       "      <td>134.100006</td>\n",
       "      <td>131.779999</td>\n",
       "      <td>133.919998</td>\n",
       "      <td>117.161659</td>\n",
       "      <td>202385700</td>\n",
       "      <td>132.373927</td>\n",
       "      <td>125.316073</td>\n",
       "      <td>1.219057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-07-05</th>\n",
       "      <td>133.779999</td>\n",
       "      <td>134.080002</td>\n",
       "      <td>133.389999</td>\n",
       "      <td>133.809998</td>\n",
       "      <td>117.065437</td>\n",
       "      <td>165936000</td>\n",
       "      <td>133.254297</td>\n",
       "      <td>124.912703</td>\n",
       "      <td>1.066618</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close   Adj Close  \\\n",
       "Date                                                                     \n",
       "2011-07-01  132.089996  134.100006  131.779999  133.919998  117.161659   \n",
       "2011-07-05  133.779999  134.080002  133.389999  133.809998  117.065437   \n",
       "\n",
       "               Volume      UpperB      LowerB  PercentB  \n",
       "Date                                                     \n",
       "2011-07-01  202385700  132.373927  125.316073  1.219057  \n",
       "2011-07-05  165936000  133.254297  124.912703  1.066618  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>UpperB</th>\n",
       "      <th>LowerB</th>\n",
       "      <th>PercentB</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2012-06-28</th>\n",
       "      <td>132.289993</td>\n",
       "      <td>132.990005</td>\n",
       "      <td>131.279999</td>\n",
       "      <td>132.789993</td>\n",
       "      <td>118.641281</td>\n",
       "      <td>169242100</td>\n",
       "      <td>136.500761</td>\n",
       "      <td>128.219241</td>\n",
       "      <td>0.551922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-29</th>\n",
       "      <td>135.199997</td>\n",
       "      <td>136.270004</td>\n",
       "      <td>134.850006</td>\n",
       "      <td>136.100006</td>\n",
       "      <td>121.598610</td>\n",
       "      <td>212250900</td>\n",
       "      <td>136.721010</td>\n",
       "      <td>128.792993</td>\n",
       "      <td>0.921670</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close   Adj Close  \\\n",
       "Date                                                                     \n",
       "2012-06-28  132.289993  132.990005  131.279999  132.789993  118.641281   \n",
       "2012-06-29  135.199997  136.270004  134.850006  136.100006  121.598610   \n",
       "\n",
       "               Volume      UpperB      LowerB  PercentB  \n",
       "Date                                                     \n",
       "2012-06-28  169242100  136.500761  128.219241  0.551922  \n",
       "2012-06-29  212250900  136.721010  128.792993  0.921670  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)\n",
    "df.shape\n",
    "df.head(2)\n",
    "df.tail(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib qt\n",
    "import mplfinance as mpf\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "setup = dict(type='candle',volume=True,returnfig=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "plot 40 data points.\n",
      "plot 70 data points.\n",
      "plot 100 data points.\n",
      "plot 130 data points.\n",
      "plot 160 data points.\n",
      "plot 190 data points.\n",
      "plot 220 data points.\n",
      "plot 250 data points.\n"
     ]
    }
   ],
   "source": [
    "data = {}\n",
    "#for num in range(30,241,30):\n",
    "for num in range(40,261,30):\n",
    "    data[num] = df.iloc[0:num]\n",
    "    print('plot',num,'data points.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['binance',\n",
       " 'blueskies',\n",
       " 'brasil',\n",
       " 'charles',\n",
       " 'checkers',\n",
       " 'classic',\n",
       " 'default',\n",
       " 'mike',\n",
       " 'nightclouds',\n",
       " 'sas',\n",
       " 'starsandstripes',\n",
       " 'yahoo']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mpf.available_styles()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "styles = [\n",
    " #'binance',\n",
    " #'blueskies',\n",
    " #'brasil',\n",
    " #'charles',\n",
    " #'checkers',\n",
    " #'classic',\n",
    " 'default',\n",
    " #'mike',\n",
    " #'nightclouds',\n",
    " #'starsandstripes',\n",
    " #'yahoo',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# numpoints = [n for n in range(30,241,30)]\n",
    "\n",
    "# volume_width     = (0.95, 0.90,  0.85,  0.80,  0.75,  0.70,  0.65, 0.60 )\n",
    "# volume_linewidth = tuple([0.65]*8)\n",
    "# candle_width     = (0.65, 0.575, 0.50, 0.425, 0.350, 0.312, 0.312, 0.321)\n",
    "# candle_linewidth = (1.00, 0.875, 0.75, 0.625, 0.500, 0.438, 0.438, 0.438)\n",
    "# ohlc_tickwidth   = tuple([0.35]*8)\n",
    "# ohlc_linewidth   = (1.50, 1.175, 0.85, 0.525, 0.525, 0.525, 0.525, 0.525)\n",
    "            \n",
    "# widths = {}\n",
    "\n",
    "# widths['vw']  = volume_width\n",
    "# widths['vlw'] = volume_linewidth\n",
    "# widths['cw']  = candle_width\n",
    "# widths['clw'] = candle_linewidth\n",
    "# widths['ow']  = ohlc_tickwidth\n",
    "# widths['olw'] = ohlc_linewidth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# widths = pd.DataFrame(widths,index=numpoints)\n",
    "# widths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# def dfinterp(df,key,column):\n",
    "#     '''\n",
    "#     Given a DataFrame, with all values and the Index as floats,\n",
    "#     and given a float key, find the row that matches the key, or \n",
    "#     find the two rows surrounding that key, and return the interpolated\n",
    "#     value for the specified column, based on where the key falls between\n",
    "#     the two rows.  If they key is an exact match for a key in the index,\n",
    "#     the return the exact value from the column.  If the key is less than\n",
    "#     or greater than any key in the index, then return either the first\n",
    "#     or last value for the column.\n",
    "#     '''\n",
    "    \n",
    "#     s = df[column]\n",
    "#     s1 = s.loc[:key]\n",
    "#     #print('s1=',s1)\n",
    "#     if len(s1) < 1:\n",
    "#         return s.iloc[0]\n",
    "#     j1 = s1.index[-1]\n",
    "#     v1 = s1.iloc[-1]\n",
    "#     #print('j1,v1=',j1,v1)\n",
    "    \n",
    "#     s2 = s.loc[key:]\n",
    "#     #print('s2=',s2)\n",
    "#     if len(s2) < 1:\n",
    "#         return s.iloc[-1]\n",
    "#     j2 = s2.index[0]\n",
    "#     v2 = s2.iloc[0]\n",
    "#     #print('j2,v2=',j2,v2)\n",
    "\n",
    "#     if j1 == j2:\n",
    "#         return v1\n",
    "#     delta   = j2 - j1\n",
    "#     portion = (key - j1)/delta\n",
    "#     #print('delta,key,portion=',delta,key,portion)\n",
    "#     return v1 + (v2-v1)*portion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "figscale = 1.0\n",
    "setup    = dict(type='candle',volume=True,mav=(10,40),returnfig=True)\n",
    "# #num      = 240\n",
    "\n",
    "# for num in range(30,241,30):\n",
    "#     for s in styles:\n",
    "# #     w = dict(vol_width=0.65      ,vol_linewidth=0.65,\n",
    "# #              candle_width=.312 ,candle_linewidth=0.438,\n",
    "# #              ohlc_ticksize=0.35 ,ohlc_linewidth=0.525)\n",
    "#         f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s)\n",
    "\n",
    "\n",
    "# #     w = dict(vol_width=0.6      ,vol_linewidth=0.65,\n",
    "# #              candle_width=.285 ,candle_linewidth=0.376,\n",
    "# #              ohlc_ticksize=0.35 ,ohlc_linewidth=0.525)\n",
    "#     #f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.9857142857142858\n",
      "candle: width = 0.5499999999999999\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 69\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.9857142857142858\n",
      "volume: width= 0.9566666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n"
     ]
    }
   ],
   "source": [
    "f,a = mpf.plot(data[70],**setup,figscale=figscale)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "=========================================\n",
      "Can we better handle the formatting here?\n",
      "So that we the same data is not labeled \n",
      "repeatedly on the x-axis?\n",
      "=========================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('''\n",
    "=========================================\n",
    "Can we better handle the formatting here?\n",
    "So that we the same data is not labeled \n",
    "repeatedly on the x-axis?\n",
    "=========================================\n",
    "''')\n",
    "#f,a = mpf.plot(data[num].iloc[0:1],**setup,figscale=figscale)\n",
    "#f,a = mpf.plot(data[num].iloc[0:1],**setup,figscale=figscale,show_nontrading=True)\n",
    "#f,a = mpf.plot(data[num].iloc[0:1],**setup,figscale=figscale,show_nontrading=True,datetime_format='%m/%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plotabunch():\n",
    "    for num in range(40,261,30):\n",
    "        for s in styles:\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s)\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s+' SNT',show_nontrading=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.975\n",
      "candle: width = 0.625\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 39\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.975\n",
      "volume: width= 0.9733333333333333\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 1.4\n",
      "candle: width = 0.90125\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 734375.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 1.4\n",
      "volume: width= 1.4035466666666665\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.9857142857142858\n",
      "candle: width = 0.5499999999999999\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 69\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.9857142857142858\n",
      "volume: width= 0.9566666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 1.4428571428571428\n",
      "candle: width = 0.8173785714285714\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 734420.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 1.4428571428571428\n",
      "volume: width= 1.4217433333333334\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 0.99\n",
      "candle: width = 0.475\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 99\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 0.99\n",
      "volume: width= 0.9416666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 1.43\n",
      "candle: width = 0.6996275\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 734462.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 1.43\n",
      "volume: width= 1.386980833333333\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 0.9923076923076923\n",
      "candle: width = 0.39999999999999997\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 129\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 0.9923076923076923\n",
      "volume: width= 0.9166666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 1.4461538461538461\n",
      "candle: width = 0.6131692307692308\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 734507.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 1.4461538461538461\n",
      "volume: width= 1.4051794871794874\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 0.99375\n",
      "candle: width = 0.3373333333333333\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 159\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 0.99375\n",
      "volume: width= 0.9\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 1.44375\n",
      "candle: width = 0.5162465\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 734550.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 1.44375\n",
      "volume: width= 1.3773375000000003\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9947368421052631\n",
      "candle: width = 0.312\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 189\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 0.9947368421052631\n",
      "volume: width= 0.8916666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 1.4526315789473685\n",
      "candle: width = 0.4804143157894737\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 734595.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 1.4526315789473685\n",
      "volume: width= 1.3729789473684213\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9954545454545455\n",
      "candle: width = 0.315\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 219\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 0.9954545454545455\n",
      "volume: width= 0.8583333333333333\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 1.45\n",
      "candle: width = 0.484155\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 734638.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 1.45\n",
      "volume: width= 1.3192583333333332\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.996\n",
      "candle: width = 0.321\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 249\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 0.996\n",
      "volume: width= 0.825\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 1.448\n",
      "candle: width = 0.49269648\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 734681.0\n",
      "plot: xdates[ 0]= 734319.0\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 1.448\n",
      "volume: width= 1.266276\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "10.5 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%matplotlib\n",
    "figscale = 1.0\n",
    "setup    = dict(type='candle',volume=True,mav=(10,40),returnfig=True)#,show_nontrading=True)\n",
    "%timeit -n1 -r1 plotabunch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-17-a6774c8535dd>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-17-a6774c8535dd>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    STOP HERE\u001b[0m\n\u001b[0m            ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "STOP HERE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "### Resample data to Weekly:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "wdf = df.resample('1W').agg(\n",
    "    {'Open'  :'first',\n",
    "     'High'  :'max',\n",
    "     'Low'   :'min',\n",
    "     'Close' :'last',\n",
    "     'Volume':'sum'\n",
    "    })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-07-03</th>\n",
       "      <td>132.089996</td>\n",
       "      <td>134.100006</td>\n",
       "      <td>131.779999</td>\n",
       "      <td>133.919998</td>\n",
       "      <td>202385700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-07-10</th>\n",
       "      <td>133.779999</td>\n",
       "      <td>135.699997</td>\n",
       "      <td>133.110001</td>\n",
       "      <td>134.399994</td>\n",
       "      <td>673832300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-07-17</th>\n",
       "      <td>132.750000</td>\n",
       "      <td>133.220001</td>\n",
       "      <td>130.679993</td>\n",
       "      <td>131.690002</td>\n",
       "      <td>1060781500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-07-24</th>\n",
       "      <td>131.080002</td>\n",
       "      <td>134.820007</td>\n",
       "      <td>129.630005</td>\n",
       "      <td>134.580002</td>\n",
       "      <td>871838100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-07-31</th>\n",
       "      <td>133.300003</td>\n",
       "      <td>134.490005</td>\n",
       "      <td>127.970001</td>\n",
       "      <td>129.330002</td>\n",
       "      <td>1031930400</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close      Volume\n",
       "Date                                                                  \n",
       "2011-07-03  132.089996  134.100006  131.779999  133.919998   202385700\n",
       "2011-07-10  133.779999  135.699997  133.110001  134.399994   673832300\n",
       "2011-07-17  132.750000  133.220001  130.679993  131.690002  1060781500\n",
       "2011-07-24  131.080002  134.820007  129.630005  134.580002   871838100\n",
       "2011-07-31  133.300003  134.490005  127.970001  129.330002  1031930400"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2012-06-03</th>\n",
       "      <td>133.160004</td>\n",
       "      <td>133.929993</td>\n",
       "      <td>128.160004</td>\n",
       "      <td>128.160004</td>\n",
       "      <td>764680800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-10</th>\n",
       "      <td>128.389999</td>\n",
       "      <td>133.529999</td>\n",
       "      <td>127.139999</td>\n",
       "      <td>133.100006</td>\n",
       "      <td>879586100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-17</th>\n",
       "      <td>134.169998</td>\n",
       "      <td>134.259995</td>\n",
       "      <td>131.160004</td>\n",
       "      <td>134.139999</td>\n",
       "      <td>923971800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-24</th>\n",
       "      <td>133.580002</td>\n",
       "      <td>136.250000</td>\n",
       "      <td>132.330002</td>\n",
       "      <td>133.460007</td>\n",
       "      <td>810496700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-07-01</th>\n",
       "      <td>132.050003</td>\n",
       "      <td>136.270004</td>\n",
       "      <td>130.850006</td>\n",
       "      <td>136.100006</td>\n",
       "      <td>777590700</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close     Volume\n",
       "Date                                                                 \n",
       "2012-06-03  133.160004  133.929993  128.160004  128.160004  764680800\n",
       "2012-06-10  128.389999  133.529999  127.139999  133.100006  879586100\n",
       "2012-06-17  134.169998  134.259995  131.160004  134.139999  923971800\n",
       "2012-06-24  133.580002  136.250000  132.330002  133.460007  810496700\n",
       "2012-07-01  132.050003  136.270004  130.850006  136.100006  777590700"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "(53, 5)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wdf.head()\n",
    "wdf.tail()\n",
    "wdf.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n"
     ]
    }
   ],
   "source": [
    "%matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "plot 8 data points.\n",
      "plot 16 data points.\n",
      "plot 24 data points.\n",
      "plot 32 data points.\n",
      "plot 40 data points.\n",
      "plot 48 data points.\n"
     ]
    }
   ],
   "source": [
    "data = {}\n",
    "#for num in range(30,241,30):\n",
    "for num in range(8,54,8):\n",
    "    data[num] = wdf.iloc[0:num]\n",
    "    print('plot',num,'data points.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# w = dict(vol_width=7.0      ,vol_linewidth=0.65,\n",
    "#          candle_width=4.2 ,candle_linewidth=1.0,\n",
    "#          ohlc_ticksize=2.5 ,ohlc_linewidth=0.525)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plotabunch():\n",
    "    for num in range(8,54,8):\n",
    "        for s in styles:\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s)\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s+' SNT',show_nontrading=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 0.875\n",
      "candle: width = 0.65\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 7\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 8\n",
      "plot: avg_dist_between_points = 0.875\n",
      "volume: width= 0.98\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 6.125\n",
      "candle: width = 4.1006875\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 734370.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 8\n",
      "plot: avg_dist_between_points = 6.125\n",
      "volume: width= 6.182575\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 0.9375\n",
      "candle: width = 0.65\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 15\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 16\n",
      "plot: avg_dist_between_points = 0.9375\n",
      "volume: width= 0.98\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 6.5625\n",
      "candle: width = 4.39359375\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 734426.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 16\n",
      "plot: avg_dist_between_points = 6.5625\n",
      "volume: width= 6.624187500000001\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 0.9583333333333334\n",
      "candle: width = 0.65\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 23\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 24\n",
      "plot: avg_dist_between_points = 0.9583333333333334\n",
      "volume: width= 0.98\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.98\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.5\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 1.0\n",
      "candle: avg_dist_between_points = 6.708333333333333\n",
      "candle: width = 4.491229166666667\n",
      "candle: linewidth = 1.0\n",
      "plot: xdates[-1]= 734482.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 24\n",
      "plot: avg_dist_between_points = 6.708333333333333\n",
      "volume: width= 6.771391666666666\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9786666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.4783333333333333\n",
      "_dfinterpolate returning 0.645\n",
      "_dfinterpolate returning 0.9916666666666667\n",
      "candle: avg_dist_between_points = 0.96875\n",
      "candle: width = 0.645\n",
      "candle: linewidth = 0.9916666666666667\n",
      "plot: xdates[-1]= 31\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 32\n",
      "plot: avg_dist_between_points = 0.96875\n",
      "volume: width= 0.9786666666666667\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9786666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.4783333333333333\n",
      "_dfinterpolate returning 0.645\n",
      "_dfinterpolate returning 0.9916666666666667\n",
      "candle: avg_dist_between_points = 6.78125\n",
      "candle: width = 4.505123437500001\n",
      "candle: linewidth = 0.9916666666666667\n",
      "plot: xdates[-1]= 734538.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 32\n",
      "plot: avg_dist_between_points = 6.78125\n",
      "volume: width= 6.835680833333334\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.975\n",
      "candle: width = 0.625\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 39\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.975\n",
      "volume: width= 0.9733333333333333\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 6.825\n",
      "candle: width = 4.39359375\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 734594.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 6.825\n",
      "volume: width= 6.842289999999999\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.968\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.305\n",
      "_dfinterpolate returning 0.605\n",
      "_dfinterpolate returning 0.925\n",
      "candle: avg_dist_between_points = 0.9791666666666666\n",
      "candle: width = 0.605\n",
      "candle: linewidth = 0.925\n",
      "plot: xdates[-1]= 47\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 48\n",
      "plot: avg_dist_between_points = 0.9791666666666666\n",
      "volume: width= 0.968\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "_dfinterpolate returning 0.968\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.305\n",
      "_dfinterpolate returning 0.605\n",
      "_dfinterpolate returning 0.925\n",
      "candle: avg_dist_between_points = 6.854166666666667\n",
      "candle: width = 4.271173958333334\n",
      "candle: linewidth = 0.925\n",
      "plot: xdates[-1]= 734650.0\n",
      "plot: xdates[ 0]= 734321.0\n",
      "plot: len(xdates)= 48\n",
      "plot: avg_dist_between_points = 6.854166666666667\n",
      "volume: width= 6.833878333333334\n",
      "volume: linewidth= 0.65\n",
      "vcolors= #1f77b4\n",
      "4.82 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%matplotlib\n",
    "figscale = 1.0\n",
    "setup    = dict(type='candle',volume=True,mav=(10,40),returnfig=True)#,show_nontrading=True)\n",
    "%timeit -n1 -r1 plotabunch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n"
     ]
    }
   ],
   "source": [
    "%matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%ls -l ../data/*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1563, 4)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-11-05 09:30:00</th>\n",
       "      <td>3080.80</td>\n",
       "      <td>3080.49</td>\n",
       "      <td>3081.47</td>\n",
       "      <td>3080.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-05 09:31:00</th>\n",
       "      <td>3080.33</td>\n",
       "      <td>3079.36</td>\n",
       "      <td>3080.33</td>\n",
       "      <td>3079.15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Open    Close     High      Low\n",
       "Date                                                   \n",
       "2019-11-05 09:30:00  3080.80  3080.49  3081.47  3080.30\n",
       "2019-11-05 09:31:00  3080.33  3079.36  3080.33  3079.15"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-11-08 15:58:00</th>\n",
       "      <td>3090.73</td>\n",
       "      <td>3091.04</td>\n",
       "      <td>3091.13</td>\n",
       "      <td>3090.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-08 15:59:00</th>\n",
       "      <td>3091.16</td>\n",
       "      <td>3092.91</td>\n",
       "      <td>3092.91</td>\n",
       "      <td>3090.96</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Open    Close     High      Low\n",
       "Date                                                   \n",
       "2019-11-08 15:58:00  3090.73  3091.04  3091.13  3090.58\n",
       "2019-11-08 15:59:00  3091.16  3092.91  3092.91  3090.96"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idf = pd.read_csv('../data/SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True)\n",
    "idf.drop('Volume',axis=1,inplace=True)\n",
    "idf.shape\n",
    "idf.head(2)\n",
    "idf.tail(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "tdf = idf.loc['2019-11-05 15:00':'2019-11-06 15:00',:]\n",
    "tdf = idf.loc['2019-11-05':'2019-11-05',:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "391"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(tdf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "plot 40 data points.\n",
      "plot 70 data points.\n",
      "plot 100 data points.\n",
      "plot 130 data points.\n",
      "plot 160 data points.\n",
      "plot 190 data points.\n",
      "plot 220 data points.\n",
      "plot 250 data points.\n"
     ]
    }
   ],
   "source": [
    "data = {}\n",
    "#for num in range(30,241,30):\n",
    "for num in range(40,261,30):\n",
    "    data[num] = tdf.iloc[0:num]\n",
    "    print('plot',num,'data points.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "styles = [\n",
    " #'binance',\n",
    " #'blueskies',\n",
    " #'brasil',\n",
    " 'charles',\n",
    " #'checkers',\n",
    " #'classic',\n",
    " 'default',\n",
    " #'mike',\n",
    " #'nightclouds',\n",
    " #'starsandstripes',\n",
    " #'yahoo',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n"
     ]
    }
   ],
   "source": [
    "%matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# w = dict(vol_width=0.00065      ,vol_linewidth=0.65,\n",
    "#          candle_width=.000312 ,candle_linewidth=0.438,\n",
    "#          ohlc_ticksize=0.00035 ,ohlc_linewidth=0.000525)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plotabunch():\n",
    "    for num in range(40,261,30):\n",
    "        for s in styles:\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s)\n",
    "            f,a = mpf.plot(data[num],**setup,figscale=figscale, style=s, title=s+' SNT',show_nontrading=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using matplotlib backend: Qt5Agg\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.975\n",
      "candle: width = 0.625\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 39\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.975\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.0006770833337213844\n",
      "candle: width = 0.00043587239608314124\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 737368.4229166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.0006770833337213844\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.975\n",
      "candle: width = 0.625\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 39\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.975\n",
      "_dfinterpolate returning 0.9733333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.3916666666666666\n",
      "_dfinterpolate returning 0.625\n",
      "_dfinterpolate returning 0.9583333333333334\n",
      "candle: avg_dist_between_points = 0.0006770833337213844\n",
      "candle: width = 0.00043587239608314124\n",
      "candle: linewidth = 0.9583333333333334\n",
      "plot: xdates[-1]= 737368.4229166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 40\n",
      "plot: avg_dist_between_points = 0.0006770833337213844\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.9857142857142858\n",
      "candle: width = 0.5499999999999999\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 69\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.9857142857142858\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.0006845238086368357\n",
      "candle: width = 0.0003877827375927674\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 737368.44375\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.0006845238086368357\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.9857142857142858\n",
      "candle: width = 0.5499999999999999\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 69\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.9857142857142858\n",
      "_dfinterpolate returning 0.9566666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 1.0666666666666667\n",
      "_dfinterpolate returning 0.5499999999999999\n",
      "_dfinterpolate returning 0.8333333333333334\n",
      "candle: avg_dist_between_points = 0.0006845238086368357\n",
      "candle: width = 0.0003877827375927674\n",
      "candle: linewidth = 0.8333333333333334\n",
      "plot: xdates[-1]= 737368.44375\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 70\n",
      "plot: avg_dist_between_points = 0.0006845238086368357\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 0.99\n",
      "candle: width = 0.475\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 99\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 0.99\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 0.0006874999997671694\n",
      "candle: width = 0.0003363593748860876\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 737368.4645833333\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 0.0006874999997671694\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 0.99\n",
      "candle: width = 0.475\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 99\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 0.99\n",
      "_dfinterpolate returning 0.9416666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.7416666666666667\n",
      "_dfinterpolate returning 0.475\n",
      "_dfinterpolate returning 0.7083333333333334\n",
      "candle: avg_dist_between_points = 0.0006874999997671694\n",
      "candle: width = 0.0003363593748860876\n",
      "candle: linewidth = 0.7083333333333334\n",
      "plot: xdates[-1]= 737368.4645833333\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 100\n",
      "plot: avg_dist_between_points = 0.0006874999997671694\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 0.9923076923076923\n",
      "candle: width = 0.39999999999999997\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 129\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 0.9923076923076923\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 0.0006891025642219644\n",
      "candle: width = 0.0002921794872301129\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 737368.4854166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 0.0006891025642219644\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 0.9923076923076923\n",
      "candle: width = 0.39999999999999997\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 129\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 0.9923076923076923\n",
      "_dfinterpolate returning 0.9166666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.39999999999999997\n",
      "_dfinterpolate returning 0.5833333333333334\n",
      "candle: avg_dist_between_points = 0.0006891025642219644\n",
      "candle: width = 0.0002921794872301129\n",
      "candle: linewidth = 0.5833333333333334\n",
      "plot: xdates[-1]= 737368.4854166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 130\n",
      "plot: avg_dist_between_points = 0.0006891025642219644\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 0.99375\n",
      "candle: width = 0.3373333333333333\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 159\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 0.99375\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 0.0006901041662786156\n",
      "candle: width = 0.0002467628470834655\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 737368.50625\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 0.0006901041662786156\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 0.99375\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "candle: width = 0.3373333333333333\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 159\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 0.99375\n",
      "_dfinterpolate returning 0.9\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.3373333333333333\n",
      "_dfinterpolate returning 0.47933333333333333\n",
      "candle: avg_dist_between_points = 0.0006901041662786156\n",
      "candle: width = 0.0002467628470834655\n",
      "candle: linewidth = 0.47933333333333333\n",
      "plot: xdates[-1]= 737368.50625\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 160\n",
      "plot: avg_dist_between_points = 0.0006901041662786156\n",
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9947368421052631\n",
      "candle: width = 0.312\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 189\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 0.9947368421052631\n",
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006907894735616681\n",
      "candle: width = 0.0002284578946963149\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.5270833333\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 0.0006907894735616681\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9947368421052631\n",
      "candle: width = 0.312\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 189\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 0.9947368421052631\n",
      "_dfinterpolate returning 0.8916666666666667\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.312\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006907894735616681\n",
      "candle: width = 0.0002284578946963149\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.5270833333\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 190\n",
      "plot: avg_dist_between_points = 0.0006907894735616681\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9954545454545455\n",
      "candle: width = 0.315\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 219\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 0.9954545454545455\n",
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006912878788584336\n",
      "candle: width = 0.00023082102275083098\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.5479166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 0.0006912878788584336\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.9954545454545455\n",
      "candle: width = 0.315\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 219\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 0.9954545454545455\n",
      "_dfinterpolate returning 0.8583333333333333\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.315\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006912878788584336\n",
      "candle: width = 0.00023082102275083098\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.5479166667\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 220\n",
      "plot: avg_dist_between_points = 0.0006912878788584336\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.996\n",
      "candle: width = 0.321\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 249\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 0.996\n",
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006916666664183139\n",
      "candle: width = 0.00023534649991549552\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.56875\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 0.0006916666664183139\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n",
      "/home/dino/code/mplfinance/src/mplfinance/plotting.py:266: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  fig = plt.figure()\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.996\n",
      "candle: width = 0.321\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 249\n",
      "plot: xdates[ 0]= 0\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 0.996\n",
      "_dfinterpolate returning 0.825\n",
      "_dfinterpolate returning 0.65\n",
      "_dfinterpolate returning 0.35\n",
      "_dfinterpolate returning 0.525\n",
      "_dfinterpolate returning 0.321\n",
      "_dfinterpolate returning 0.438\n",
      "candle: avg_dist_between_points = 0.0006916666664183139\n",
      "candle: width = 0.00023534649991549552\n",
      "candle: linewidth = 0.438\n",
      "plot: xdates[-1]= 737368.56875\n",
      "plot: xdates[ 0]= 737368.3958333334\n",
      "plot: len(xdates)= 250\n",
      "plot: avg_dist_between_points = 0.0006916666664183139\n",
      "4.05 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%matplotlib\n",
    "figscale = 1.0\n",
    "setup    = dict(type='candle',mav=(10,40),returnfig=True)#,show_nontrading=True)\n",
    "%timeit -n1 -r1 plotabunch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mplfinance._helpers import _adjust_color_brightness"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = ['w','k','w','k','w','k']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ac = _adjust_color_brightness('#181818',1.0)\n",
    "ac\n",
    "ac = _adjust_color_brightness('#181818',0.9)\n",
    "ac"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for x in ac:\n",
    "    if x == (0,0,0):\n",
    "        print('black')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "STOP HERE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
